import 'package:flutter/material.dart';

class ThreeCallBack extends StatefulWidget {
  const ThreeCallBack({Key? key}) : super(key: key);

  @override
  State<ThreeCallBack> createState() => _ThreeCallBackState();
}

class _ThreeCallBackState extends State<ThreeCallBack> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: [
          Test(
            onVoidCallback: (){
              print("没有参数且不返回数据的回调的签名:===== onVoidCallback");
            },
            onCallback: (int value1, String value2){
              print("===== ${value1} ${value2}");
            },
            onValueChanged: (String value3){
              print("ValueChanged===== ${value3}");
            },
            onTap: (int value1, String value2){
              print("Function===== ${value1} ${value2}");
            },
          ),
        ],
      ),
    );
  }
}

typedef CallbackCallback =  void Function(int value1, String value2);

class Test extends StatefulWidget {
  VoidCallback? onVoidCallback;
  CallbackCallback? onCallback;
  ValueChanged<String>? onValueChanged;
  void Function(int value1, String value2)? onTap;
  Test({Key? key,this.onVoidCallback,this.onCallback,this.onValueChanged,this.onTap}) : super(key: key);

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        GestureDetector(
          onTap: (){
            widget.onVoidCallback!();
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.purpleAccent,
          ),
        ),
        GestureDetector(
          onTap: (){
            widget.onCallback!(1,"onCallback");
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.red,
          ),
        ),
        GestureDetector(
          onTap: (){
            widget.onValueChanged!("onValueChanged");
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.green,
          ),
        ),
        GestureDetector(
          onTap: (){
            widget.onTap!(1,"onCallback");
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.blue,
          ),
        ),
      ],
    );
  }
}
